package com.song.rabbitmq.springbootorderrabbitmqproducerttl.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * 死信队列：消息超过过期时间后就会进入死信队列
 *
 * 消息被拒绝、消息过期、队列达到最大长度
 */

@Configuration
public class DeadRabbitConfig {

    // 创建交换机
    @Bean
    DirectExchange deadExchange() {
        return new DirectExchange("dead_direct_exchange");
    }


    // 创建队列
    @Bean
    public Queue deadQueue() {
        return new Queue("dead.direct.queue", true);
    }


    // 绑定队列到交换机，并设置相应的routing key，来控制哪部分队列应该接收到消息
    @Bean
    public Binding deadbinds() {
        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with("dead");
    }


}
